
//
//  PayModel.m
//  DaJiang
//
//  Created by sally on 16/12/11.
//  Copyright © 2016年 jiniu. All rights reserved.
//

#import "PayInterface.h"
#import "PayModel.h"

@implementation PayModel

+ (BOOL)propertyIsOptional:(NSString *)propertyName {
  return YES;
}

//支付宝预支付
+ (void)payAlipayPrepayWithOrderId:(NSString *)orderId
                           subject:(NSString *)subject
                          totalFee:(NSString *)totalFee
                        completion:(void (^)(PayModel *payModel))completion {
  [self cleanLastError];

  completion_t _completion = ^(NSDictionary *resultObject, NSInteger code, NSString *description) {
    PayModel *payModel = nil;

    if (code == SUCCESS_RESULT) {
      payModel = [[PayModel alloc] initWithDictionary:resultObject error:nil];
    } else {
      [self setLastError:[NSError errorWithDomain:description code:code userInfo:nil]];
    }

    completion(payModel);
  };

  error_t _error = ^(NSError *error) {
    [self setLastError:error];
    completion(nil);
  };

  PayInterface *interface = [[PayInterface alloc] init];
  [interface payAlipayPrepayWithOrderId:orderId subject:subject totalFee:totalFee completion:_completion error:_error];
}

@end
